package com.reebake.ideal.storage.client;

import com.reebake.ideal.storage.entity.FileInfoDTO;
import com.reebake.ideal.storage.entity.FileListViewDTO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * 文件操作客户端
 */
public interface FileOperationClient {

    @GetMapping("file-info-by-url")
    public FileInfoDTO fileInfo(@RequestParam String url);

    public default FileInfoDTO fileInfo(String path, String filename) {
        return fileInfo(null, path, filename);
    }

    @GetMapping("file-info-by-filename")
    public FileInfoDTO fileInfo(@RequestParam String platform, @RequestParam String path, @RequestParam String filename);

    /**
     * 文件是否存在
     * @param url
     */
    @PostMapping("exists-by-url")
    public Boolean exists(@RequestParam String url);

    public default Boolean exists(String path, String filename) {
        return exists(null, path, filename);
    }

    @PostMapping("exists-by-filename")
    public Boolean exists(@RequestParam String platform, @RequestParam String path, @RequestParam String filename);


    /**
     * 删除文件
     * @param url
     */
    @PostMapping("delete-by-url")
    public void delete(@RequestParam String url);

    public default void delete(String path, String filename) {
        delete(null, path, filename);
    }

    @PostMapping("delete-by-filename")
    public void delete(@RequestParam String platform, @RequestParam String path, @RequestParam String filename);


    public default FileInfoDTO copy(String url, String path) {
        return copy(url, null, path);
    }

    /**
     * 复制文件
     * @param url
     * @param platform
     * @param path
     * @return 新的文件信息
     */
    @PostMapping("copy")
    public FileInfoDTO copy(@RequestParam String url, @RequestParam String platform, @RequestParam String path);

    public default FileInfoDTO move(String url, String path) {
        return move(url, null, path);
    }

    /**
     * 移动文件
     * @param url
     * @param platform
     * @param path
     * @return 新的文件信息
     */
    @PostMapping("move")
    public FileInfoDTO move(@RequestParam String url, @RequestParam String platform, @RequestParam String path);

    public default FileListViewDTO list(String path, String marker, Integer maxFiles) {
        return  list(null, path, marker, maxFiles);
    }
    @GetMapping("list")
    public FileListViewDTO list(@RequestParam String platform, @RequestParam String path, @RequestParam String marker, @RequestParam Integer maxFiles);
}
